package com.happok.onlineclass.usermanagement.verifycode.controller;

import com.happok.onlineclass.usermanagement.setting.dto.VerifySmsDTO;
import com.happok.onlineclass.usermanagement.verifycode.dto.FunctionVerifyCodeDTO;
import com.happok.onlineclass.usermanagement.verifycode.dto.TemplateVerifyCodeDTO;
import com.happok.onlineclass.usermanagement.verifycode.service.VerifyCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 验证码
 * 验证码相关
 *
 * @author : chenac
 * @module 在线课堂/用户管理
 * @date : 2021/10/8 12:16
 */
@RestController
@Api(tags = "验证码")
@RequestMapping(value = "/user-management/verify-code")
public class VerifyCodeController {

    @Autowired
    private VerifyCodeService verifyCodeService;

    /**
     * 获取验证码-功能
     * 按照功能分类获取验证码<br>
     * 20000,获取验证码成功<br>
     * 44900,请***秒后重新获取<br>
     * 40500,邮箱或短信服务器设置异常<br>
     * 41901,验证码发送失败<br>
     * 50000,服务端异常
     *
     * @param verifyCodeDTO
     * @author: chenac
     * @date: 14:15
     * @execption:
     * @return: void
     */
    @GetMapping(value = "/function/v1")
    @ApiOperation(value = "获取验证码-功能分类")
    @ApiResponses({
            @ApiResponse(code = 20000, message = "获取验证码成功"),
            @ApiResponse(code = 44900, message = "请***秒后重新获取"),
            @ApiResponse(code = 40500, message = "邮箱或短信服务器设置异常"),
            @ApiResponse(code = 41901, message = "验证码发送失败"),
            @ApiResponse(code = 50000, message = "服务端异常"),
    })
    public void getFunctionVerifyCode(FunctionVerifyCodeDTO verifyCodeDTO) {
        verifyCodeService.getFunctionVerifyCode(verifyCodeDTO);
    }

    /**
     * 获取验证码-模板
     * 按照模板code获取验证码<br>
     * 20000,获取验证码成功<br>
     * 44900,请***秒后重新获取<br>
     * 40500,邮箱或短信服务器设置异常<br>
     * 41901,验证码发送失败<br>
     * 50000,服务端异常
     *
     * @param verifyCodeDTO 获取验证码参数
     * @author: chenac
     * @date: 14:15
     * @execption:
     * @return: void
     */
    @GetMapping(value = "/template/v1")
    @ApiOperation(value = "获取验证码-模板code")
    @ApiResponses({
            @ApiResponse(code = 20000, message = "获取验证码成功"),
            @ApiResponse(code = 44900, message = "请***秒后重新获取"),
            @ApiResponse(code = 40500, message = "邮箱或短信服务器设置异常"),
            @ApiResponse(code = 41901, message = "验证码发送失败"),
            @ApiResponse(code = 50000, message = "服务端异常"),
    })
    public void getTemplateVerifyCode(TemplateVerifyCodeDTO verifyCodeDTO) {
        verifyCodeService.getTemplateVerifyCode(verifyCodeDTO);
    }

    /**
     * 测试短信验证
     * 20000,测试短信验证成功<br>
     * 40000,参数异常<br>
     * 41201,验证码不正确<br>
     * 41202,验证码失效<br>
     * 50000,服务端异常
     *
     * @param verifySms
     * @author: chenac
     * @date: 18:10
     * @execption:
     * @return: void
     */
    @PostMapping(value = "/template/v1")
    @ApiOperation(value = "测试短信验证")
    @ApiResponses({
            @ApiResponse(code = 20000, message = "测试短信验证成功"),
            @ApiResponse(code = 40000, message = "参数异常"),
            @ApiResponse(code = 41201, message = "验证码不正确"),
            @ApiResponse(code = 41202, message = "验证码失效"),
            @ApiResponse(code = 50000, message = "服务端异常")
    })
    public void verificationSms(@RequestBody @Valid VerifySmsDTO verifySms) {
        verifyCodeService.verificationSms(verifySms);
    }
}